package com.example.safe.keyboard;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.safe.keyboard.R;
import com.example.safe.keyboard.databinding.ActivityScrollTestBinding;
import com.surfin.safe.keyboard.SafeKeyboard;

public class ScrollTestActivity extends AppCompatActivity {

    public static void start(Context context) {
        context.startActivity(new Intent(context, ScrollTestActivity.class));
    }

    private SafeKeyboard safeKeyboard;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityScrollTestBinding binding = ActivityScrollTestBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setTitle(R.string.keyboard_scrollview_test);
        // 配合ScrollView使用的时候，需要传入scrollView对象，才能在输入的时候让界面向上滑动，看到EditText
        safeKeyboard = new SafeKeyboard(this, binding.ctlKeyboardContainer,
                binding.ctlRoot, binding.scrollView);
        safeKeyboard.putEditText(binding.etText);
        safeKeyboard.putRandomEdit(binding.etNumber);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (safeKeyboard != null) {
            safeKeyboard.release();
            safeKeyboard = null;
        }
    }
}
